// 源插件
import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import router from 'umi/router';

// 视图插件
import {
  Spin,
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Steps,
  Radio,
  Upload,
} from 'antd';

// 外部组件
import StandardTable from '@/components/StandardTable';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

// css OR less预编译器

// 图片

const FormItem = Form.Item;
const { Option } = Select;

/**
 *  Created by xjc on 2019/8/15
 *  Describe:数据连接
 */

@connect(({ aqdq, loading }) => ({
  aqdq,
  loading: loading.models.aqdqRule,
}))
@Form.create()
class UpdateDQ extends PureComponent {
  componentWillMount() {}

  /**
   *  Created by xjc on 2019/8/15
   *  Describe:当前状态
   */

  state = {
    confirmLoading: false,
  };

  onChange = e => {};

  okHandle() {
    const that = this;
    that.setState({
      confirmLoading: true,
    });
    return new Promise((resolve, reject) => {
      setTimeout(resolve, 800);
    })
      .then(() => {
        that.setState({
          confirmLoading: false,
        });
        that.props.form.validateFields((err, values) => {
          if (!err) {
            const { dispatch } = that.props;
            dispatch({
              type: 'aqdq/UpdateAQDQ',
              payload: {
                id: that.props.row.id,
                // toStrikeRate: Number(values.toStrikeRate),
                // nowPrice: Number(values.nowPrice),
                ko: Number(values.ko),
                strike: Number(values.strike),
                referencePrice: Number(values.referencePrice),
                edate: values.edate.format('YYYY-MM-DD'),
                // edate: new Date(values.edate.format('YYYY-MM-DD').replace(/-/g,'/')).getTime(),
                sdate: values.sdate.format('YYYY-MM-DD'),
                normalNums: Number(values.normalNums),
                code: values.code,
                bank: values.bank,
                type: values.type,
                codeMarket: Number(values.codeMarket),
              },
              callback: res => {
                that.props.closeVisbile();
              },
            });
          }
        });
      })
      .catch(() => console.log('Oops errors!'));
  }

  cancelHandle() {
    this.props.closeVisbile();
  }

  render() {
    const { confirmLoading } = this.state;
    const { visible, form, row } = this.props;
    const { getFieldDecorator } = form;

    return (
      <Modal
        destroyOnClose
        title="修改"
        visible={visible}
        width="60%"
        centered
        onOk={this.okHandle.bind(this)}
        confirmLoading={confirmLoading}
        onCancel={this.cancelHandle.bind(this)}
      >
        <Form onSubmit={this.handleSearch} style={{ overflowY: 'scroll' }}>
          <Row>
            <FormItem label="类型" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('type', { initialValue: row.type })(
                <Select style={{ width: '85%' }}>
                  <Option value="AQ">AQ</Option>
                  <Option value="DQ">DQ</Option>
                </Select>
              )}
            </FormItem>
            <FormItem label="银行" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('bank', { initialValue: row.bank })(
                <Select style={{ width: '85%' }}>
                  <Option value="瑞银">瑞银</Option>
                  <Option value="中银">中银</Option>
                  <Option value="花旗">花旗</Option>
                </Select>
              )}
            </FormItem>
            <FormItem label="股票" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('code', { initialValue: row.code })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            <FormItem label="股票市场" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('codeMarket', { initialValue: (row.codeMarket || '').toString() })(
                <Select style={{ width: '85%' }}>
                  <Option value="1">美股</Option>
                  <Option value="2">港股</Option>
                </Select>
              )}
            </FormItem>
            <FormItem label="每日股数" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('normalNums', { initialValue: row.normalNums })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            <FormItem label="开始日期" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {form.getFieldDecorator('sdate', {
                initialValue: moment(row.sdate),
                rules: [{ type: 'object' }],
              })(
                <DatePicker
                  style={{ width: '85%' }}
                  // showTime
                  format="YYYY-MM-DD"
                  placeholder="开始日期"
                />
              )}
            </FormItem>
            <FormItem label="结束日期" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {form.getFieldDecorator('edate', {
                initialValue: moment(row.edate),
                rules: [{ type: 'object' }],
              })(
                <DatePicker
                  style={{ width: '85%' }}
                  // showTime
                  format="YYYY-MM-DD"
                  placeholder="结束日期"
                />
              )}
            </FormItem>
            <FormItem label="参考价" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('referencePrice', { initialValue: row.referencePrice })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            <FormItem label="执行价" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('strike', { initialValue: row.strike })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            <FormItem label="KO价" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('ko', { initialValue: row.ko })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            {/* <FormItem label="现价" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('nowPrice', { initialValue: row.nowPrice })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            <FormItem label="距执幅度" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('toStrikeRate', { initialValue: row.toStrikeRate })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem>
            <FormItem label="距KO幅度" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
              {getFieldDecorator('toKoRate', { initialValue: row.toKoRate })(
                <Input style={{ width: '85%' }} placeholder="" />
              )}
            </FormItem> */}
          </Row>
        </Form>
      </Modal>
    );
  }

  componentDidMount() {}

  componentWillUnmount() {}
}

export default UpdateDQ;
